Added I18N support for Xen-API error codes.
authorEwan Mellor <ewan@xensource.com>
Sat, 23 Dec 2006 11:24:10 +0000 (11:24 +0000)
committerEwan Mellor <ewan@xensource.com>
Sat, 23 Dec 2006 11:24:10 +0000 (11:24 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/Makefile
tools/python/xen/xm/XenAPI.py
tools/python/xen/xm/main.py
tools/python/xen/xm/messages/en/xen-xm.po [new file with mode: 0644]

index 6b84446ee68c5cef4c7aa36e08bec656a4646d15..3732c06aa99ce225bdbfd02740ca4dec0ca6f26c 100644 (file)
@@ -7,16 +7,26 @@ all: build
 .PHONY: build
 build:
        CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
+       for file in `cd xen/xm; find messages -name xen-xm.po`; do \
+            dest=`echo "build/$$file" | \
+                  sed -e 's#xen-xm.po#LC_MESSAGES/xen-xm.mo#'`; \
+            mkdir -p `dirname "$$dest"`; \
+            msgfmt -c -o "$$dest" "xen/xm/$$file"; \
+        done
 
 .PHONY: install
 ifndef XEN_PYTHON_NATIVE_INSTALL
-install: all
+install: install-messages
        CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --prefix="" --force
 else
-install: all
+install: install-messages
        CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" --force
 endif
 
+install-messages: all
+       mkdir -p "$(DESTDIR)/usr/share/locale"
+       cp -R build/messages/* "$(DESTDIR)/usr/share/locale/"
+
 .PHONY: test
 test:
        export LD_LIBRARY_PATH=$$(readlink -f ../libxc):$$(readlink -f ../xenstore); python test.py -b -u
index cd794087c31f9ba5e6ebb7540c32c1953619b294..c2a9d0ce3386891fc6d87fac679a637edbb2dbb3 100644 (file)
 # OF THIS SOFTWARE.
 # --------------------------------------------------------------------
 
+import gettext
 import xmlrpclib
 
 import xen.util.xmlrpclib2
 
 
+gettext.install('xen-xm')
+
 class Failure(Exception):
     def __init__(self, details):
         self.details = details
 
     def __str__(self):
-        return "Xen-API failure: %s" % str(self.details)
+        try:
+            return _(self.details[0]) % self._details_map()
+        except TypeError, exn:
+            return "Message database broken: %s.\nXen-API failure: %s" % \
+                   (exn, str(self.details))
+        except Exception, exn:
+            import sys
+            print >>sys.stderr, exn
+            return "Xen-API failure: %s" % str(self.details)
+
+    def _details_map(self):
+        return dict([(str(i), self.details[i])
+                     for i in range(len(self.details))])
 
 
 class Session(xen.util.xmlrpclib2.ServerProxy):
index 450d7973549087f13da60de348625d9561cf16ad..5f27680a5e5122ece8398182093a2f1b8ce11bcf 100644 (file)
@@ -1780,7 +1780,7 @@ def _run_cmd(cmd, cmd_name, args):
     except SystemExit, code:
         return code == 0, code
     except XenAPI.Failure, exn:
-        err(str(exn))
+        print >>sys.stderr, str(exn)
     except xmlrpclib.Fault, ex:
         if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
             err("Domain '%s' does not exist." % ex.faultString)
diff --git a/tools/python/xen/xm/messages/en/xen-xm.po b/tools/python/xen/xm/messages/en/xen-xm.po
new file mode 100644 (file)
index 0000000..75d7f5e
--- /dev/null
@@ -0,0 +1,67 @@
+# ============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# ============================================================================
+# Copyright (c) 2006 XenSource Inc.
+# ============================================================================
+# 
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Xen-xm 3.0\n"
+"PO-Revision-Date: 2006-12-23 11:04+0000\n"
+"Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
+"Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=ASCII\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "INTERNAL_ERROR"
+msgstr "Internal error: %(1)s."
+
+msgid "MAP_DUPLICATE_KEY"
+msgstr "This map already contains %(1)s -> %(2)s."
+
+msgid "MESSAGE_METHOD_UNKNOWN"
+msgstr "The method %(1)s is unsupported."
+
+msgid "MESSAGE_PARAMETER_COUNT_MISMATCH"
+msgstr "The method %(1)s takes %(2)s argument(s) (%(3)s given)."
+
+msgid "SESSION_AUTHENTICATION_FAILED"
+msgstr "Permission denied."
+
+msgid "HOST_CPU_HANDLE_INVALID"
+msgstr "The host_cpu handle %(1)s is invalid."
+
+msgid "HOST_HANDLE_INVALID"
+msgstr "The host handle %(1)s is invalid."
+
+msgid "SR_HANDLE_INVALID"
+msgstr "The SR handle %(1)s is invalid."
+
+msgid "VBD_HANDLE_INVALID"
+msgstr "The VBD handle %(1)s is invalid."
+
+msgid "VDI_HANDLE_INVALID"
+msgstr "The VDI handle %(1)s is invalid."
+
+msgid "VIF_HANDLE_INVALID"
+msgstr "The VIF handle %(1)s is invalid."
+
+msgid "VM_HANDLE_INVALID"
+msgstr "The VM handle %(1)s is invalid."
+
+msgid "VTPM_HANDLE_INVALID"
+msgstr "The VTPM handle %(1)s is invalid."
+